<?php

declare(strict_types=1);

namespace App\Custom;

use App\Constants\Keywords;
use Hyperf\Context\Context;
use Hyperf\Utils\Coroutine;
use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;

class AppendRequestIdProcessor implements ProcessorInterface
{
    public function __invoke(array|LogRecord $record)
    {
        $record['extra']['request_id'] = Context::get(Keywords::REQUEST_ID);
        $record['extra']['lang'] = Context::get(Keywords::LANG);
        $record['extra']['coroutine_id'] = \Hyperf\Coroutine\Coroutine::id();
        return $record;
    }
}